home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Evaluate
/
QueueStack.h
< prev
next >
Wrap
Text File
|
1991-05-17
|
3KB
|
88 lines
/****************************************************************************************
*
*
* QueueStack.c -Generic Stack and Queue Routines
*
* ©1993, Graham Cox. Based on some work by Stephen Baxter, Ian Marshall et. al.
*
****************************************************************************************/
#define NIL 0L
#define QueueType 0
#define StackType 1
typedef struct
{
struct QSElem **nextItem; // Handle to next item in queue or stack
int qElemType; // Type of data this record holds
long qData; // the data. If < 4 bytes, this is the value, else address.
long qFlags; // reserved. Do not use.
}
QSElem, *QSElemPtr, **QSElemHdl;
typedef struct
{
int StructType; // Queue or Stack
QSElemHdl QSHead; // Handle to top of stack or last item in queue
QSElemHdl QSTail; // Handle to first item in queue, not used for stack
long reserved; // not used (yet!)
}
QSRec, *QSPtr, **QSHandle;
/* data types that can be stacked or queued */
#define QSInteger 0 // LoWord of qData contains value
#define QSLong 1 // qData contains data
#define QSFloat 2 // qData contains handle of constant (float)
#define QSOperator 3 // qData contains operator token in low 8 bits.
#define QSVariable 4 // qData contains handle of variable (float + name)
#define QSString 5 // qData contains handle of pascal string
#define QSTabVar 6 // qData is index into variable table for this one
// other types may be added later- type codes > 6 are reserved.
/* function prototypes */
QSHandle NewQSStruct(int sqType);
// creates new queue or stack structure
void DisposeQSStruct(QSHandle theQS);
// disposes struct and any data in it
QSElemHdl NewQSItem(int qsType,long qsData);
// creates new element with data supplied
void DisposeQSItem(QSElemHdl theItem);
// disposes of the item structure. If addresses are
// referred to, you have to deal with that...
void PushQSItem(QSElemHdl theItem,QSHandle theQS);
// pushes item onto stack or queue
QSElemHdl PopQSItem(QSHandle theQS);
// pops item from queue or stack. Note- depends on the
// type which item you get...
QSElemHdl PeekQSItem(QSHandle theQS);
// as above but does not adjust structure
Boolean EmptyQSStruct(QSHandle theQS);
// returns TRUE if nothing in queue/stack, else FALSE
long QSLength(QSHandle theQS);
// returns the number of items in the queue/stack.